//
//  CellOfDiscount_topicHead.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/9.
//  Copyright © 2016年 KX. All rights reserved.
#import "UIImageView+WebCache.h"
#import "Masonry.h"
#import "FreeTravelMacro.h"
#import "CellOfDiscount_topicHead.h"
#import "WebViewOfCommendViewController.h"
#import "TravelShopViewController.h"
@interface CellOfDiscount_topicHead ()
@property (nonatomic, strong) UILabel *labelOfTitle;
@property (nonatomic, strong) UIImageView *imageViewOfPhoto;
@end
@implementation CellOfDiscount_topicHead
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.labelOfTitle = [[UILabel alloc]init];
        self.imageViewOfPhoto = [[UIImageView alloc]init];
        [self addSubview:self.labelOfTitle];
        [self addSubview:self.imageViewOfPhoto];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self.imageViewOfPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.top.equalTo(self.mas_top).mas_offset(50);
    }];
    [self.labelOfTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.bottom.equalTo(self.imageViewOfPhoto.mas_top);
    }];
    self.labelOfTitle.textAlignment = NSTextAlignmentCenter;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goTap:)];
    self.imageViewOfPhoto.userInteractionEnabled = YES;
    [self.imageViewOfPhoto addGestureRecognizer:tap];
}
- (void)goTap:(UITapGestureRecognizer *)tap{
    WebViewOfCommendViewController *vc = [[WebViewOfCommendViewController alloc]init];
    vc.url = self.model.link_url;
    
    TravelShopViewController *travel = (TravelShopViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder;
    [travel.navigationController pushViewController:vc animated:YES];
}
- (void)setModel:(ModelOfDiscount_topic *)model{
    _model = model;
    self.labelOfTitle.text = model.title;
    [self.imageViewOfPhoto sd_setImageWithURL:[NSURL URLWithString:model.photo]];
}
@end
